<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ajax
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Ajax extends CI_Controller {

    //put your code here


    function ajax() {
        parent :: __construct();
        //put your code here
    }

    function populate_car_version() {
        $model = $_GET['model'];
        $sql = "Select * from version where model_id=$model and status=51 order by version ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>
        <select name="car_version" style="width: 200px">
            <option value="" selected="selected">Version</option>
            <option value="" disabled="disabled"></option>
            <?php
            foreach ($result as $version): {
                    ?>
                    <option value=<?= $version->id; ?> > <?= $version->version; ?></option>
                    <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }

    function populate_cal_model() {
       
        $make = $_GET['make'];
        $sql = "Select * from model where make_id=$make and status=51 order by model ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>
        <select name="car_model" style="width: 200px" onChange="getCarVersion(this.value,'<?= base_url(); ?>');">>
            <option value="" selected="selected" >Model</option>
            <option value="" disabled="disabled">----------------</option>
            <?php
            foreach ($result as $model): {
                    ?>
                    <option value=<?= $model->id; ?> > <?= $model->model; ?></option>
                    <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }

//=========LOCATION ===========================================//

    function populate_state() {
        $countryID = $_GET['country'];
        $sql = "Select id,state from state where country_id=$countryID and status=51 order by state ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>

        <select name="car_state" style="width: 200px" onChange="getCity(this.value,'<?= base_url(); ?>');">
            <option value="" selected="selected">State</option>
            <option value="" disabled="disabled">----------------</option>
            <?php
            foreach ($result as $state): {
                    ?>
                    <option value=<?= $state->id; ?> > <?= $state->state; ?></option>
                    <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }

    function populate_city() {
        $stateID = $_GET['state'];
        $sql = "Select id,city from city where state_id=$stateID and status=51 order by city ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>
        <select name="car_city" style="width: 200px">
            <option value="" selected="selected">City</option>
            <option value="" disabled="disabled">----------------</option>
            <?php
            foreach ($result as $city): {
                    ?>
                    <option value=<?= $city->id; ?> > <?= $city->city; ?></option>
                    <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }

    function populate_city_individial() {
        $stateID = $_GET['state'];

        $sql = "Select id,city from city where state_id=$stateID and status=51 order by city ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>

        <select name="ind_city">
            <option value="" selected="selected">City</option>
            <option value="" disabled="disabled">----------------</option>
            <?php
            foreach ($result as $city): {
                    ?>
                    <option value=<?= $city->id; ?> > <?= $city->city; ?></option>
                    <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }

    function populate_city_dealer() {
        $stateID = $_GET['state'];

        $sql = "Select id,city from city where state_id=$stateID and status=51 order by city ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>

        <select name="del_city">
            <option value="" selected="selected">City</option>
            <option value="" disabled="disabled">----------------</option>
            <?php
            foreach ($result as $city): {
                    ?>
                    <option value=<?= $city->id; ?> > <?= $city->city; ?></option>
                    <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }

    
}
?>
